namespace WebRtcProject.Models.Configuration
{
    /// <summary>
    /// WebRTC 专用 RabbitMQ 配置
    /// 针对嵌入式设备语音通话的信令传输优化
    /// </summary>
    public class WebRtcRabbitMQOptions
    {
        public const string SectionName = "WebRtcRabbitMQ";
        
        /// <summary>
        /// 是否启用 WebRTC 专用服务
        /// </summary>
        public bool Enabled { get; set; } = true;
        
        /// <summary>
        /// WebRTC 信令配置
        /// </summary>
        public WebRtcSignalingOptions Signaling { get; set; } = new();
        
        /// <summary>
        /// 嵌入式设备配置
        /// </summary>
        public EmbeddedDeviceOptions EmbeddedDevices { get; set; } = new();
        
        /// <summary>
        /// 性能优化配置
        /// </summary>
        public WebRtcPerformanceOptions Performance { get; set; } = new();
    }

    /// <summary>
    /// WebRTC 信令传输配置
    /// </summary>
    public class WebRtcSignalingOptions
    {
        /// <summary>
        /// 启用高优先级消息处理
        /// </summary>
        public bool EnableHighPriority { get; set; } = true;
        
        /// <summary>
        /// Offer/Answer 消息优先级 (0-255)
        /// </summary>
        public byte OfferAnswerPriority { get; set; } = 255;
        
        /// <summary>
        /// ICE 候选消息优先级 (0-255)
        /// </summary>
        public byte IceCandidatePriority { get; set; } = 200;
        
        /// <summary>
        /// 房间事件消息优先级 (0-255)
        /// </summary>
        public byte RoomEventPriority { get; set; } = 100;
        
        /// <summary>
        /// 信令消息生存时间 (毫秒)
        /// </summary>
        public int SignalingTTL { get; set; } = 10000; // 10秒
        
        /// <summary>
        /// 使用直连队列模式 (跳过交换机路由)
        /// </summary>
        public bool UseDirectQueues { get; set; } = true;
        
        /// <summary>
        /// 设备队列名称前缀
        /// </summary>
        public string QueuePrefix { get; set; } = "rtc.device";
        
        /// <summary>
        /// 队列最大消息数量
        /// </summary>
        public int MaxQueueLength { get; set; } = 100;
        
        /// <summary>
        /// 队列溢出策略 (drop-head, reject-publish)
        /// </summary>
        public string OverflowStrategy { get; set; } = "drop-head";
    }

    /// <summary>
    /// 嵌入式设备管理配置
    /// </summary>
    public class EmbeddedDeviceOptions
    {
        /// <summary>
        /// 最大支持设备数量
        /// </summary>
        public int MaxDevices { get; set; } = 1000;
        
        /// <summary>
        /// 设备心跳间隔
        /// </summary>
        public TimeSpan DeviceHeartbeatInterval { get; set; } = TimeSpan.FromSeconds(30);
        
        /// <summary>
        /// 设备离线超时时间
        /// </summary>
        public TimeSpan DeviceOfflineTimeout { get; set; } = TimeSpan.FromMinutes(2);
        
        /// <summary>
        /// 设备注册队列
        /// </summary>
        public string RegistrationQueue { get; set; } = "rtc.device.registration";
        
        /// <summary>
        /// 设备状态队列
        /// </summary>
        public string StatusQueue { get; set; } = "rtc.device.status";
        
        /// <summary>
        /// 自动清理离线设备
        /// </summary>
        public bool AutoCleanupOfflineDevices { get; set; } = true;
        
        /// <summary>
        /// 设备类型配置
        /// </summary>
        public Dictionary<string, DeviceTypeConfig> DeviceTypes { get; set; } = new()
        {
            ["voice_phone"] = new DeviceTypeConfig 
            { 
                MaxConcurrentCalls = 1, 
                SupportedCodecs = ["PCMU", "PCMA", "G722"],
                RequiredBandwidth = 64 // kbps
            },
            ["conference_device"] = new DeviceTypeConfig 
            { 
                MaxConcurrentCalls = 10, 
                SupportedCodecs = ["PCMU", "PCMA", "G722", "Opus"],
                RequiredBandwidth = 128 // kbps
            }
        };
    }

    /// <summary>
    /// 设备类型配置
    /// </summary>
    public class DeviceTypeConfig
    {
        /// <summary>
        /// 最大并发通话数
        /// </summary>
        public int MaxConcurrentCalls { get; set; } = 1;
        
        /// <summary>
        /// 支持的音频编解码器
        /// </summary>
        public List<string> SupportedCodecs { get; set; } = new();
        
        /// <summary>
        /// 所需带宽 (kbps)
        /// </summary>
        public int RequiredBandwidth { get; set; } = 64;
        
        /// <summary>
        /// 自定义配置
        /// </summary>
        public Dictionary<string, object> CustomConfig { get; set; } = new();
    }

    /// <summary>
    /// WebRTC 性能优化配置
    /// </summary>
    public class WebRtcPerformanceOptions
    {
        /// <summary>
        /// 预取消息数量
        /// </summary>
        public ushort PrefetchCount { get; set; } = 50;
        
        /// <summary>
        /// 使用非持久化消息 (提升性能)
        /// </summary>
        public bool UseNonPersistentMessages { get; set; } = true;
        
        /// <summary>
        /// 启用消息批处理
        /// </summary>
        public bool EnableBatching { get; set; } = true;
        
        /// <summary>
        /// 批处理大小
        /// </summary>
        public int BatchSize { get; set; } = 10;
        
        /// <summary>
        /// 批处理超时 (毫秒)
        /// </summary>
        public int BatchTimeout { get; set; } = 50;
        
        /// <summary>
        /// 启用延迟监控
        /// </summary>
        public bool EnableLatencyMonitoring { get; set; } = true;
        
        /// <summary>
        /// 延迟阈值告警 (毫秒)
        /// </summary>
        public int LatencyThreshold { get; set; } = 100;
    }
} 